package org.HisCanvas.ChrisRiffle.JFlightLog.swingUi.recordDetailWindow;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.DateFormatter;

import org.HisCanvas.ChrisRiffle.JFlightLog.common.LogBookRecUtils;
import org.HisCanvas.ChrisRiffle.JFlightLog.persist.LogBookDbConstants;



/**
 * 
 * @author RIF
 *
 */
public class LogBookRecPanel extends JPanel implements LogBookDbConstants{

	
	 private JLabel remarksLabel = new JLabel(LogBookRecUtils.getFieldShortName(REMARKS));  
	 private JLabel totalHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(TOTAL_HOURS));   
	 private JLabel soloLabel = new JLabel(LogBookRecUtils.getFieldShortName(SOLO));   
	 private JLabel sicHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(SECOND_IN_COMMAND_HOURS));   
	 private JLabel picLabel = new JLabel(LogBookRecUtils.getFieldShortName(PILOT_IN_COMMAND_HOURS));   
	 private JLabel dualGivenLabel = new JLabel(LogBookRecUtils.getFieldShortName(DUAL_INSTRUCTION_GIVEN_HOURS));
	 private JLabel dualReceivedLabel = new JLabel(LogBookRecUtils.getFieldShortName(DUAL_INSTRUCTION_RECEIVED_HOURS));   
	 private JLabel simulatorLabel = new JLabel(LogBookRecUtils.getFieldShortName(SIMULATOR_HOURS));   
	 private JLabel safetyPilotLabel = new JLabel(LogBookRecUtils.getFieldShortName(SAFETY_PILOT_NAME)); 
	 private JLabel iapNamesLabel = new JLabel(LogBookRecUtils.getFieldShortName(INSTRUMENT_APPROACHES_NAMES));   
	 private JLabel iapCountLabel = new JLabel(LogBookRecUtils.getFieldShortName(INSTRUMENT_APPROACHES_COUNT));   
	 private JLabel simInstrumentHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(INSTRUMENT_SIMULATED_HOURS));   
	 private JLabel actualInstrumentLabel = new JLabel(LogBookRecUtils.getFieldShortName(INSTRUMENT_ACTUAL_HOURS));
	 
	 
	 private JLabel nightHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(NIGHT_HOURS));   
	 private JLabel dayHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(DAY_HOURS));   
	 private JLabel xCountryHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(CROSS_COUNTRY_HOURS)); 
	 private JLabel multiEngineHoursLabel = new JLabel(LogBookRecUtils.getFieldShortName(MULTI_ENGINE_HOURS));  
	 private JLabel singleEngineLabel = new JLabel(LogBookRecUtils.getFieldShortName(SINGLE_ENGINE_HOURS));   
	 private JLabel landingsNightCountLabel = new JLabel(LogBookRecUtils.getFieldShortName(LANDINGS_NIGHT_COUNT));  
	 private JLabel landingsDayCountLabel = new JLabel(LogBookRecUtils.getFieldShortName(LANDINGS_DAY_COUNT));  
	 private JLabel landingsTotalCountLabel = new JLabel(LogBookRecUtils.getFieldShortName(LANDINGS_TOTAL_COUNT));   
	 private JLabel arrivalAirportcodeLabel = new JLabel(LogBookRecUtils.getFieldShortName(ARRIVAL_AIRPORT_CODE));   
	 private JLabel departureAirportCodeLabel = new JLabel(LogBookRecUtils.getFieldShortName(DEPARTURE_AIRPORT_CODE)); 
	 private JLabel aircraftRegistrationLabel = new JLabel(LogBookRecUtils.getFieldShortName(AIRCRAFT_REGISTRATION));  
	 private JLabel aircraftTypeLabel = new JLabel(LogBookRecUtils.getFieldShortName(AIRCRAFT_TYPE));  
	 private JLabel dateOfFlightLabel = new JLabel(LogBookRecUtils.getFieldShortName(DATE_OF_FLIGHT));
    
	 private JFormattedTextField remarksTxtField;  
	 private JFormattedTextField totalHoursTxtField;   
	 private JFormattedTextField soloTxtField;   
	 private JFormattedTextField sicHoursTxtField;   
	 private JFormattedTextField picTxtField;   
	 private JFormattedTextField dualGivenTxtField;
	 private JFormattedTextField dualReceivedTxtField;   
	 private JFormattedTextField simulatorTxtField;   
	 private JFormattedTextField safetyPilotTxtField; 
	 private JFormattedTextField iapNamesTxtField;   
	 private JFormattedTextField iapCountTxtField;   
	 private JFormattedTextField simInstrumentHoursTxtField;   
	 private JFormattedTextField actualInstrumentTxtField;   
	 
	 
	 private JFormattedTextField nightHoursTxtField;   
	 private JFormattedTextField dayHoursTxtField;   
	 private JFormattedTextField xCountryHoursTxtField; 
	 private JFormattedTextField multiEngineHoursTxtField;  
	 private JFormattedTextField singleEngineTxtField;   
	 private JFormattedTextField landingsNightCountTxtField;  
	 private JFormattedTextField landingsDayCountTxtField;  
	 private JFormattedTextField landingsTotalCountTxtField;   
	 private JFormattedTextField arrivalAirportcodeTxtField;   
	 private JFormattedTextField departureAirportCodeTxtField; 
	 private JFormattedTextField aircraftRegistrationTxtField;  
	 private JFormattedTextField aircraftTypeTxtField;  
	 private JFormattedTextField dateOfFlightTxtField;
	 

	 
	 
	 
	 /**
	 * 
	 */
	public LogBookRecPanel() {
	    init();
	}
	 
	 
	 
	 private void init(){
	     	     
	     
	     GroupLayout groupLayout = new GroupLayout(this);
	     setLayout(groupLayout);
	     
	     groupLayout.setAutoCreateGaps(true);
	     
	   //horizontal group
	     groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
	     					
	     	.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
	     	  .addComponent(dateOfFlightLabel)
	     	  .addComponent(aircraftTypeLabel)
	     	  .addComponent(aircraftRegistrationLabel)
	     	  .addComponent(departureAirportCodeLabel)
	     	  .addComponent(arrivalAirportcodeLabel)
	     	  .addComponent(landingsTotalCountLabel)
	     	  .addComponent(landingsDayCountLabel)
	     	  .addComponent(landingsNightCountLabel)
	     	  .addComponent(singleEngineLabel)
	     	  .addComponent(multiEngineHoursLabel)
	     	  .addComponent(soloLabel)
	     	  .addComponent(dayHoursLabel)
	     	  .addComponent(nightHoursLabel)
	     	)
	     					
	     	.addGroup(groupLayout.createParallelGroup()
	     	  .addComponent(getDateOfFlightTxtField())
	     	  .addComponent(getAircraftTypeTxtField())	
	     	  .addComponent(getAircraftRegistrationTxtField())
	     	  .addComponent(getDepartureAirportCodeTxtField())
	     	  .addComponent(getArrivalAirportcodeTxtField())
	     	  .addComponent(getLandingsTotalCountTxtField())
	     	  .addComponent(getLandingsDayCountTxtField())
	     	  .addComponent(getLandingsNightCountTxtField())
	     	  .addComponent(getSingleEngineTxtField())
	     	  .addComponent(getMultiEngineHoursTxtField())
	     	  .addComponent(getSoloTxtField())
	     	  .addComponent(getDayHoursTxtField())
	     	  .addComponent(getNightHoursTxtField())
	     	)
	     	
	     	
	     	
	     	
	     	.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
	     	  .addComponent(actualInstrumentLabel)		
	     	  .addComponent(simInstrumentHoursLabel)
	     	  .addComponent(iapCountLabel)
	     	  .addComponent(iapNamesLabel)
	     	  .addComponent(safetyPilotLabel)
	     	  .addComponent(simulatorLabel)
	     	  .addComponent(dualReceivedLabel)
	     	  .addComponent(dualGivenLabel)
	     	  .addComponent(picLabel)
	     	  .addComponent(sicHoursLabel)
	     	  .addComponent(xCountryHoursLabel)
	     	  .addComponent(totalHoursLabel)
	     	  .addComponent(remarksLabel)
	     	)
	     	
	     	.addGroup(groupLayout.createParallelGroup()
	     	  .addComponent(getActualInstrumentTxtField())
	     	  .addComponent(getSimInstrumentHoursTxtField())
	     	  .addComponent(getIapCountTxtField())
	     	  .addComponent(getIapNamesTxtField())
	     	  .addComponent(getSafetyPilotTxtField())
	     	  .addComponent(getSimulatorTxtField())
	     	  .addComponent(getDualReceivedTxtField())
	     	  .addComponent(getDualGivenTxtField())
	     	  .addComponent(getPicTxtField())
	     	  .addComponent(getSicHoursTxtField())
	     	  .addComponent(getxCountryHoursTxtField())
	     	  .addComponent(getTotalHoursTxtField())
	     	  .addComponent(getRemarksTxtField())
	     	)						
	     	
	     	
	     );
	     
	     
	     
	     //****************************************************************
	     //****************************************************************
	     //				vertical group
	     //****************************************************************
	     //****************************************************************
	     
	     groupLayout.setVerticalGroup(groupLayout.createSequentialGroup()

	     .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	       .addComponent(dateOfFlightLabel)
	       .addComponent(getDateOfFlightTxtField())
	       .addComponent(actualInstrumentLabel)
	       .addComponent(getActualInstrumentTxtField())
	     )	

	     .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	       .addComponent(aircraftTypeLabel)	
	       .addComponent(getAircraftTypeTxtField())
	       .addComponent(simInstrumentHoursLabel)
	       .addComponent(getSimInstrumentHoursTxtField())
	     )	
	     
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(aircraftRegistrationLabel)
	      .addComponent(getAircraftRegistrationTxtField())
	      .addComponent(iapCountLabel)
	      .addComponent(getIapCountTxtField())
	    )
	    
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(departureAirportCodeLabel)
	      .addComponent(getDepartureAirportCodeTxtField())
	      .addComponent(iapNamesLabel)
	      .addComponent(getIapNamesTxtField())
	    )

	    
	   .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(arrivalAirportcodeLabel)
	      .addComponent(getArrivalAirportcodeTxtField())
	      .addComponent(safetyPilotLabel)
	      .addComponent(getSafetyPilotTxtField())
	    )
	    
	    
	   .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(landingsTotalCountLabel)
	      .addComponent(getLandingsTotalCountTxtField())
	      .addComponent(simulatorLabel)
	      .addComponent(getSimulatorTxtField())
	    )
	    
	    
	   .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(landingsDayCountLabel)
	      .addComponent(getLandingsDayCountTxtField())
	      .addComponent(dualReceivedLabel)
	      .addComponent(getDualReceivedTxtField())
	    )
	    	    
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(landingsNightCountLabel)
	      .addComponent(getLandingsNightCountTxtField())
	      .addComponent(dualGivenLabel)
	      .addComponent(getDualGivenTxtField())
	    )
	    
	   .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(singleEngineLabel)
	      .addComponent(getSingleEngineTxtField())
	      .addComponent(picLabel)
	      .addComponent(getPicTxtField())
	    )
	    
	    
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(multiEngineHoursLabel)
	      .addComponent(getMultiEngineHoursTxtField())
	      .addComponent(sicHoursLabel)
	      .addComponent(getSicHoursTxtField())
	    )
	    
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(xCountryHoursLabel)
	      .addComponent(getxCountryHoursTxtField())
	      .addComponent(soloLabel)
	      .addComponent(getSoloTxtField())
	    )	    
	    
	    
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(dayHoursLabel)
	      .addComponent(getDayHoursTxtField())
	      .addComponent(totalHoursLabel)
	      .addComponent(getTotalHoursTxtField())
	    )
	    
	    .addGroup(groupLayout.createParallelGroup(Alignment.CENTER, false)
	      .addComponent(nightHoursLabel)
	      .addComponent(getNightHoursTxtField())
	      .addComponent(remarksLabel)
	      .addComponent(getRemarksTxtField())
	    )	    
	    
     );
	    
	    
    
	 }
	 
	 
	 	

	 
	 
	/**
	 * Gets the remarksTxtField
	 * 
	 * @return the remarksTxtField
	 */
	public JFormattedTextField getRemarksTxtField() {
		if (remarksTxtField == null) {
			remarksTxtField = new JFormattedTextField();
		}
		return remarksTxtField;
	}

	/**
	 * Gets the totalHoursTxtField
	 * 
	 * @return the totalHoursTxtField
	 */
	public JFormattedTextField getTotalHoursTxtField() {
		if (totalHoursTxtField == null) {
			totalHoursTxtField = new JFormattedTextField(floatNf);												
		}
		return totalHoursTxtField;
	}
	
	/**
	 * Gets the soloTxtField
	 * 
	 * @return the soloTxtField
	 */
	public JFormattedTextField getSoloTxtField() {
		if (soloTxtField == null) {
			soloTxtField = new JFormattedTextField(floatNf);
		}
		return soloTxtField;
	}

	/**
	 * Gets the sicHoursTxtField
	 * 
	 * @return the sicHoursTxtField
	 */
	public JFormattedTextField getSicHoursTxtField() {
		if (sicHoursTxtField == null) {
			sicHoursTxtField = new JFormattedTextField(floatNf);
		}
		return sicHoursTxtField;
	}

	/**
	 * Gets the picTxtField
	 * 
	 * @return the picTxtField
	 */
	public JFormattedTextField getPicTxtField() {
		if (picTxtField == null) {
			picTxtField = new JFormattedTextField(floatNf);
		}
		return picTxtField;
	}
	
	/**
	 * Gets the dualGivenTxtField
	 * 
	 * @return the dualGivenTxtField
	 */
	public JFormattedTextField getDualGivenTxtField() {
		if (dualGivenTxtField == null) {
			dualGivenTxtField = new JFormattedTextField(floatNf);
		}
		return dualGivenTxtField;
	}

	/**
	 * Gets the dualReceivedTxtField
	 * 
	 * @return the dualReceivedTxtField
	 */
	public JFormattedTextField getDualReceivedTxtField() {
		if (dualReceivedTxtField == null) {
			dualReceivedTxtField = new JFormattedTextField(floatNf);
		}
		return dualReceivedTxtField;
	}

	/**
	 * Gets the simulatorTxtField
	 * 
	 * @return the simulatorTxtField
	 */
	public JFormattedTextField getSimulatorTxtField() {
		if (simulatorTxtField == null) {
			simulatorTxtField = new JFormattedTextField(floatNf);
		}
		return simulatorTxtField;
	}
	
	/**
	 * Gets the safetyPilotTxtField
	 * 
	 * @return the safetyPilotTxtField
	 */
	public JFormattedTextField getSafetyPilotTxtField() {
		if (safetyPilotTxtField == null) {
			safetyPilotTxtField = new JFormattedTextField();
		}
		return safetyPilotTxtField;
	}

	/**
	 * Gets the iapNamesTxtField
	 * 
	 * @return the iapNamesTxtField
	 */
	public JFormattedTextField getIapNamesTxtField() {
		if (iapNamesTxtField == null) {
			iapNamesTxtField = new JFormattedTextField();
		}
		return iapNamesTxtField;
	}

	/**
	 * Gets the iapCountTxtField
	 * 
	 * @return the iapCountTxtField
	 */
	public JFormattedTextField getIapCountTxtField() {
		if (iapCountTxtField == null) {
			iapCountTxtField = new JFormattedTextField(intNf);
		}
		return iapCountTxtField;
	}
	
	/**
	 * Gets the simInstrumentHoursTxtField
	 * 
	 * @return the simInstrumentHoursTxtField
	 */
	public JFormattedTextField getSimInstrumentHoursTxtField() {
		if (simInstrumentHoursTxtField == null) {
			simInstrumentHoursTxtField = new JFormattedTextField(floatNf);
		}
		return simInstrumentHoursTxtField;
	}

	/**
	 * Gets the actualInstrumentTxtField
	 * 
	 * @return the actualInstrumentTxtField
	 */
	public JFormattedTextField getActualInstrumentTxtField() {
		if (actualInstrumentTxtField == null) {
			actualInstrumentTxtField = new JFormattedTextField(floatNf);
		}
		return actualInstrumentTxtField;
	}

	/**
	 * Gets the nightHoursTxtField
	 * 
	 * @return the nightHoursTxtField
	 */
	public JFormattedTextField getNightHoursTxtField() {
		if (nightHoursTxtField == null) {
			nightHoursTxtField = new JFormattedTextField(floatNf);
		}
		return nightHoursTxtField;
	}

	/**
	 * Gets the dayHoursTxtField
	 * 
	 * @return the dayHoursTxtField
	 */
	public JFormattedTextField getDayHoursTxtField() {
		if (dayHoursTxtField == null) {
			dayHoursTxtField = new JFormattedTextField(floatNf);
		}
		return dayHoursTxtField;
	}

	/**
	 * Gets the xCountryHoursTxtField
	 * 
	 * @return the xCountryHoursTxtField
	 */
	public JFormattedTextField getxCountryHoursTxtField() {
		if (xCountryHoursTxtField == null) {
			xCountryHoursTxtField = new JFormattedTextField(floatNf);
		}
		return xCountryHoursTxtField;
	}

	/**
	 * Gets the multiEngineHoursTxtField
	 * 
	 * @return the multiEngineHoursTxtField
	 */
	public JFormattedTextField getMultiEngineHoursTxtField() {
		if (multiEngineHoursTxtField == null) {
			multiEngineHoursTxtField = new JFormattedTextField(floatNf);
		}
		return multiEngineHoursTxtField;
	}

	/**
	 * Gets the singleEngineTxtField
	 * 
	 * @return the singleEngineTxtField
	 */
	public JFormattedTextField getSingleEngineTxtField() {
		if (singleEngineTxtField == null) {
			singleEngineTxtField = new JFormattedTextField(floatNf);
		}
		return singleEngineTxtField;
	}

	/**
	 * Gets the landingsNightCountTxtField
	 * 
	 * @return the landingsNightCountTxtField
	 */
	public JFormattedTextField getLandingsNightCountTxtField() {
		if (landingsNightCountTxtField == null) {
			landingsNightCountTxtField = new JFormattedTextField(intNf);
		}
		return landingsNightCountTxtField;
	}

	/**
	 * Gets the landingsDayCountTxtField
	 * 
	 * @return the landingsDayCountTxtField
	 */
	public JFormattedTextField getLandingsDayCountTxtField() {
		if (landingsDayCountTxtField == null) {
			landingsDayCountTxtField = new JFormattedTextField(intNf);
		}
		return landingsDayCountTxtField;
	}

	
	private static NumberFormat intNf = NumberFormat.getInstance();
	
	private static NumberFormat floatNf = NumberFormat.getInstance();
	
	static{
				
		intNf.setMaximumFractionDigits(0);
		
		
		floatNf.setMaximumFractionDigits(1);
		
	}
	
	
	/**
	 * Gets the landingsTotalCountTxtField
	 * 
	 * @return the landingsTotalCountTxtField
	 */
	public JFormattedTextField getLandingsTotalCountTxtField() {
		if (landingsTotalCountTxtField == null) {
			landingsTotalCountTxtField = new JFormattedTextField(floatNf);
		}
		return landingsTotalCountTxtField;
	}

	/**
	 * Gets the arrivalAirportcodeTxtField
	 * 
	 * @return the arrivalAirportcodeTxtField
	 */
	public JFormattedTextField getArrivalAirportcodeTxtField() {
		if (arrivalAirportcodeTxtField == null) {
			arrivalAirportcodeTxtField = new JFormattedTextField();
		}
		return arrivalAirportcodeTxtField;
	}

	/**
	 * Gets the departureAirportCodeTxtField
	 * 
	 * @return the departureAirportCodeTxtField
	 */
	public JFormattedTextField getDepartureAirportCodeTxtField() {
		if (departureAirportCodeTxtField == null) {
			departureAirportCodeTxtField = new JFormattedTextField();
		}
		return departureAirportCodeTxtField;
	}

	/**
	 * Gets the aircraftRegistrationTxtField
	 * 
	 * @return the aircraftRegistrationTxtField
	 */
	public JFormattedTextField getAircraftRegistrationTxtField() {
		if (aircraftRegistrationTxtField == null) {
			aircraftRegistrationTxtField = new JFormattedTextField();
		}
		return aircraftRegistrationTxtField;
	}

	/**
	 * Gets the aircraftTypeTxtField
	 * 
	 * @return the aircraftTypeTxtField
	 */
	public JFormattedTextField getAircraftTypeTxtField() {
		if (aircraftTypeTxtField == null) {
			aircraftTypeTxtField = new JFormattedTextField();
		}
		return aircraftTypeTxtField;
	}

	
	/**
	 * Gets the dateOfFlightTxtField
	 * 
	 * @return the dateOfFlightTxtField
	 */
	public JFormattedTextField getDateOfFlightTxtField() {
		if (dateOfFlightTxtField == null) {
			dateOfFlightTxtField = new JFormattedTextField(
					new DateFormatter(new SimpleDateFormat("mm/dd/yyyy")).getFormat());						
		}
		return dateOfFlightTxtField;
	}
	

	 
	 
	/**
	 * Tester
	 * @param args
	 */
	 public static void main(String[] args) {
	    
	     LogBookRecPanel p = new LogBookRecPanel();
	     JFrame f = new JFrame();
	     f.setContentPane(p);
	     f.setLocationRelativeTo(null);
	     f.pack();
	     f.addWindowListener(new WindowAdapter(){
		@Override
		public void windowClosing(WindowEvent e) {		 
		    System.exit(0);
		}
	     });
	     f.setVisible(true);	     	     
	}
	 
		 
}
